package com.reremouse.rerebbs.dao.impl;

import com.reremouse.rerebbs.dao.IDictCityDAO;
import com.reremouse.rerebbs.model.DictCity;
import org.springframework.context.ApplicationContext;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.io.Serializable;
import java.util.List;

public class DictCityDAO
        implements IDictCityDAO, Serializable {
    @PersistenceContext
    private EntityManager entityManager;
    public static final String _SCITYNAME = "SCityname";
    public static final String _NPROVID = "NProvid";
    public static final String _SSTATE = "SState";

    public EntityManager getEntityManager() {
        return this.entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public void save(DictCity entity) {
        try {
            this.entityManager.persist(entity);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    public void delete(DictCity entity) {
        try {
            entity = (DictCity) this.entityManager.getReference(DictCity.class, entity.getNCityid());
            this.entityManager.remove(entity);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    public DictCity update(DictCity entity) {
        try {
            return (DictCity) this.entityManager.merge(entity);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    public DictCity findById(Integer id) {
        try {
            return (DictCity) this.entityManager.find(DictCity.class, id);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    public List<DictCity> findByProperty(String propertyName, Object value, int... rowStartIdxAndCount) {
        try {
            String queryString = "select model from DictCity model where model." + propertyName + "= :propertyValue";

            Query query = this.entityManager.createQuery(queryString);
            query.setParameter("propertyValue", value);
            if ((rowStartIdxAndCount != null) && (rowStartIdxAndCount.length > 0)) {
                int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
                if (rowStartIdx > 0) {
                    query.setFirstResult(rowStartIdx);
                }
                if (rowStartIdxAndCount.length > 1) {
                    int rowCount = Math.max(0, rowStartIdxAndCount[1]);
                    if (rowCount > 0) {
                        query.setMaxResults(rowCount);
                    }
                }
            }
            return query.getResultList();
        } catch (RuntimeException re) {
            throw re;
        }
    }

    public List<DictCity> findBySCityname(Object SCityname, int... rowStartIdxAndCount) {
        return findByProperty("SCityname", SCityname, rowStartIdxAndCount);
    }

    public List<DictCity> findByNProvid(Object NProvid, int... rowStartIdxAndCount) {
        return findByProperty("NProvid", NProvid, rowStartIdxAndCount);
    }

    public List<DictCity> findBySState(Object SState, int... rowStartIdxAndCount) {
        return findByProperty("SState", SState, rowStartIdxAndCount);
    }

    public List<DictCity> findAll(int... rowStartIdxAndCount) {
        try {
            String queryString = "select model from DictCity model";
            Query query = this.entityManager.createQuery("select model from DictCity model");
            if ((rowStartIdxAndCount != null) && (rowStartIdxAndCount.length > 0)) {
                int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
                if (rowStartIdx > 0) {
                    query.setFirstResult(rowStartIdx);
                }
                if (rowStartIdxAndCount.length > 1) {
                    int rowCount = Math.max(0, rowStartIdxAndCount[1]);
                    if (rowCount > 0) {
                        query.setMaxResults(rowCount);
                    }
                }
            }
            return query.getResultList();
        } catch (RuntimeException re) {
            throw re;
        }
    }

    public static IDictCityDAO getFromApplicationContext(ApplicationContext ctx) {
        return (IDictCityDAO) ctx.getBean("DictCityDAO");
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.dao.impl.DictCityDAO

 * JD-Core Version:    0.7.0.1

 */